package dev.ece.suit.loader.models.dae;

import java.util.Map;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.lang3.StringUtils;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="library_materials")
public class DAEMeterials {

	@XmlElement(name="material")
	private DAEMaterial[] material;
	
	public void fillMaterialIndexMap(Map<String, Integer> materialIndexMap) {
		if(material != null) {
			Integer index = null;
			for(DAEMaterial material: this.material) {
				index = materialIndexMap.get(material.getInstance_effect().getUrl());
				materialIndexMap.put(StringUtils.join("#", material.getId()), index);
			}
		}
	}
	
	public DAEMaterial[] getMaterial() {
		return material;
	}

	public void setMaterial(DAEMaterial[] material) {
		this.material = material;
	}

	@XmlAccessorType(XmlAccessType.FIELD)
	@XmlRootElement(name="material")
	public static class DAEMaterial {
		
		@XmlAttribute(name="id")
		private String id;
		
		@XmlAttribute(name="name")
		private String name;
		
		@XmlElement(name="instance_effect")
		private DAEUrl instance_effect;

		public String getId() {
			return id;
		}

		public void setId(String id) {
			this.id = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public DAEUrl getInstance_effect() {
			return instance_effect;
		}

		public void setInstance_effect(DAEUrl instance_effect) {
			this.instance_effect = instance_effect;
		}
		
	}
}
